
use "s3data.dta"

*Partisan identity
gen PID=pid
recode PID 1=2 2=6 3/4=4
recode PID 2=1 if pidd==1
recode PID 6=7 if pidr==1
recode PID 4=3 if pidi==1
recode PID 4=5 if pidi==2
replace PID=(PID-4)/3
recode PID -1/-.5=1 -.4/.4=2 .5/1=3, gen(PID3)
recode ideo 1/3=1 4=2 5/7=3, gen(ideo3)

*pretreatment group attitudes
rename groups_pre_2 mormon_fav_pre
replace mormon_fav_pre=mormon_fav_pre/100

*policy attitudes. high = oppose policy
recode environ_pos (8=6) (9=7), gen(env_pos)
replace env_pos=(env_pos-4)/3
gen env_imp=(environ_imp-1)/4
gen env_mc=(environ_mc-1)/4
gen env_attext=(env_imp + env_mc)/2

*policy attitude moderator
gen env_mod=env_pos*env_attext

*outcome variables
gen morm_values=(mormon_values-1)/4
gen morm_close=(mormon_close-1)/3
gen morm_fav=(mormons_fav-7)/-6
gen MormDV=(morm_values+morm_close+morm_fav)/3
alpha morm_values morm_close morm_fav, item casewise

*treatment condition
gen MormTreat=.
replace MormTreat=0 if groupcond=="control"
replace MormTreat=1 if groupcond=="treatment"

*manipulation checks
recode mormons_check (4=5) (5=4) (6=3) (7=2) (8=1), gen(MormPID)
recode mormons_enviro (4=5) (5=4) (6=3) (7=2) (8=1), gen(MormENV)


************
* analysis *
************

*table a1. manipulation checks
reg MormPID MormTreat
reg MormENV MormTreat

*table a4. main analyses
reg MormDV i.MormTreat##c.env_mod PID mormon_fav_pre
est store m1

margins, dydx(MormTreat) at(env_mod=(-1(.2)1))
marginsplot, yline(0) recast(line) recastci(rarea) ciopts(col(gs10%30)) xtitle("Environmental Regulation") xlab(-1 `""Strongly" "support""' -.5 " " 0 "Neither" .5 " " 1 `""Strongly" "oppose""') xsc(titlegap(2)) ytitle("Marginal Treatment Effect", size(small)) title("") subtitle("Attitudes Toward Mormons")  addplot(hist env_mod, freq yaxis(2) yscale(alt axis(2)) ytitle("Frequency", axis(2) size(small)) fcolor(none) bcolor(gs5%40)) legend(off) saving(s3.gph, replace)

*creating figure 1
graph combine s1.gph s2.gph s3.gph, rows(1) ysize(4) xsize(12) saving(figure1.gph, replace)

*just FAV as DV
reg morm_fav i.MormTreat##c.env_mod PID mormon_fav_pre
est store m3

*just CLOSE as DV
reg morm_close i.MormTreat##c.env_mod PID mormon_fav_pre
est store m4

*just VALUES as DV
reg morm_values i.MormTreat##c.env_mod PID mormon_fav_pre
est store m5

*robustness
reg MormDV i.MormTreat##c.env_mod i.MormTreat##c.PID mormon_fav_pre
est store m2

esttab m1 m2 m3 m4 m5, drop(0.MormTreat*) se(2) b(2) r2(2)


** CACE **
recode MormENV 4/5=1 1/3=0, gen(MormENV_di)
tab MormENV_di MormTreat, col chi2

*favor
reg MormENV_di MormTreat if env_pos<0
reg MormDV MormTreat if env_pos<0
ivregress 2sls MormDV (MormENV_di=MormTreat) if env_pos<0


*oppose
reg MormENV_di MormTreat if env_pos>0
reg MormDV MormTreat if env_pos>0
ivregress 2sls MormDV (MormENV_di=MormTreat) if env_pos>0


*table a1. demographics
tab sex
sum age, detail
tab race
tab educ
tab PID3
tab ideo3